package edu.ccut.saturn.studio.wfg.dialog.vocationallogicdialog;

import org.eclipse.jface.viewers.ICellModifier;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.widgets.TableItem;

import edu.ccut.saturn.studio.wfg.wfgmodel.ExtendAttributeForLogicKey;

public class MyCellModifierExtendAttributeForLogicKey implements ICellModifier {
	
	private TableViewer tableViewer;
	
	public MyCellModifierExtendAttributeForLogicKey(TableViewer tableViewer){
		this.tableViewer = tableViewer;
	}

	public boolean canModify(Object element, String property) {
		return true;
	}

	public Object getValue(Object element, String property) {
		ExtendAttributeForLogicKey o = (ExtendAttributeForLogicKey)element;
		if(property.equals("id")){
			return o.getId();
		} else if (property.equals("parameter")){
			return o.getParameter();
		}
		throw new RuntimeException("" + property); 
	}

	public void modify(Object element, String property, Object value) {
		TableItem item = (TableItem) element;
		ExtendAttributeForLogicKey o = (ExtendAttributeForLogicKey)item.getData();
		if(property.equals("parameter")){
			String newParameter = (String) value;
			o.setParameter(newParameter);
		} else {
			throw new RuntimeException("" + property); 
		}
		
		tableViewer.update(o, null);
	}
}
